"""
编程实现：循环输入10个人的信息（姓名，年龄，性别，身高），并存储到数据库中
create   table  person(
	username  varchar(20),
	age   int,
	sex 	  char(4),
	high  double(3,2)     # 总共3位数字，2位小数
)
"""
import pymysql
if __name__ == '__main__':
    db=pymysql.connect(
        host='localhost',
        user='root',
        password='123456',
        database='test_db',
        port=3306,
        charset='utf8')
    cursor=db.cursor()
    # sql_create="create table person(username varchar(20),age int,sex char(4), high decimal(3,2))"
    # cursor.execute(sql_create)
    # db.commit()
    for i in range(3):
        s=input('请输入姓名，年龄，性别，身高：(逗号隔开)')
        name,age,sex,high=s.split(',')
        sql_insert=f'insert into person values("{name}",{int(age)},"{sex}",{round(float(high),2)})'
        cursor.execute(sql_insert)
    cursor.close()
    db.commit()
    db.close()